using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace WindowsApplication1
{
    public partial class FormCustomerChoose : Form
    {
        Database db;
        public string CustomerName="";
        public string D_CustomerId = "0";
        public FormCustomerChoose()
        {
            InitializeComponent();
        }

        private void FormCustomerChoose_Load(object sender, EventArgs e)
        {
            Rectangle srec = Screen.GetBounds(this);
            this.DesktopLocation = new Point((srec.Width - this.Width) / 2, (srec.Height - this.Height) / 2);
            this.FormBorderStyle = FormBorderStyle.FixedSingle;

            db = DatabaseFactory.CreateDatabase("Connection0");

            dataGridView1.AutoGenerateColumns = false;
            StringBuilder sb = new StringBuilder();
            sb.Append(string.Format("SELECT CustomerId,[Name] CustomerName  FROM [dbo].[Customers] where  [Name] like '%{0}%'", CustomerName));

           
            dataGridView1.DataSource = db.ExecuteDataSet(CommandType.Text, sb.ToString()).Tables[0];
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            D_CustomerId = dataGridView1.CurrentRow.Cells["CustomerId"].Value.ToString();
            CustomerName = dataGridView1.CurrentRow.Cells[1].Value.ToString();
            this.Close();
        }
    }
}